script_enemy_main{

let playsound=0;
let angle1=rand(0,360);

let shot1=0;
let bullet1=[];
let bounce1=[];

let character="Ryo";
let cutin=character;
let dispelled=0;
let spellcards=1;
let damagerate=10;
let outfit=4;
outfit=(128*outfit)-128;
let usespell=0;
let frame=0; let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEthrow1=("\script\SoundEffects\throw1.wav");
let SEreflect2=("\script\SoundEffects\reflect2.wav");
let SEshots5=("script\SoundEffects\shots5.wav");

let GRboss=("\script\Images\CharacterSprites\Ryo.png");

#include_function "script/Functions/HealthBarLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsRyo1.txt");

	LoadSE("\script\SoundEffects\throw1.wav");
	LoadSE("\script\SoundEffects\reflect2.wav");
	LoadSE("script\SoundEffects\shots5.wav");
	LoadGraphic("\script\Images\CharacterSprites\Ryo.png");

	SetLife(200);
	SetTimer(40);
	SetInvincibility(120);
	SetDamageRate(10,10); 
	SetEnemyMarker(true);
	MagicCircle(true);
	SetMovePosition02(cx,miny+100,50);
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(64,64,64,64);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=5; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

HealthBar();

if(time%200==0 && time>=60){
	if(GetPlayerX>minx+50 && GetPlayerX<maxx-50){
	SetMovePosition01(GetPlayerX+rand(-30,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX<=minx+50){
	SetMovePosition01(GetPlayerX+rand(15,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX>=maxx-50){
	SetMovePosition01(GetPlayerX-rand(15,30),rand(miny+60,miny+120),1.5);
	}
}


if(GetCommonData("Difficulty")==1){

if(time%10==0 && time>=60){
let angle=0;
	loop(12){
	let color=200+50*cos(angle*3);
	SetShotColor(color,color,color);
	CreateShot01(GetX,GetY-15,2+0.5*cos(angle*3)+rand(0,0.3),angle+angle1+rand(-2,2),25,0);
	SetShotColor(255,255,255);
	angle+=360/12;
	}
angle1-=5;
PlaySE(SEshots5);
}

if(time%90==0 && time>=90){
let angle=90-35+rand(-10,10);
	loop(8){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX-10,GetY-25);
	Obj_SetAngle(shot1,angle);
	Obj_SetSpeed(shot1,2);
	ObjShot_SetGraphic(shot1,39);
	bullet1=bullet1~[shot1];
	bounce1=bounce1~[shot1];
	bounce1[length(bullet1)-1]=0;
	angle+=70/7;
	}
PlaySE(SEthrow1);
usespell=20;
}

let i=0;
while (i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){ bullet1=erase(bullet1,i); bounce1=erase(bounce1,i); i--; }
	else{
		let obj=bullet1[i];
		if(Obj_GetX(obj)<=minx && bounce1[i]==0){
		Obj_SetAngle(obj,180-Obj_GetAngle(obj));
		Obj_SetX(obj,Obj_GetX(obj)+1); ObjShot_SetGraphic(bullet1[i],38); bounce1[i]=1;
		if(playsound==0){ PlaySE(SEreflect2); playsound=7; }
		}
		if(Obj_GetX(obj)>=maxx && bounce1[i]==0){
		Obj_SetAngle(obj,180-Obj_GetAngle(obj));
		Obj_SetX(obj,Obj_GetX(obj)-1); ObjShot_SetGraphic(bullet1[i],38); bounce1[i]=1;
		if(playsound==0){ PlaySE(SEreflect2); playsound=7; }
		}
	}
i++;
}
if(playsound>0){ playsound--; } if(playsound<0){ playsound=0; }

} //Easy

//=============================================================================================================

if(GetCommonData("Difficulty")==2){

if(time%8==0 && time>=60){
let angle=0;
	loop(13){
	let color=200+50*cos(angle*3);
	SetShotColor(color,color,color);
	CreateShot01(GetX,GetY-15,2+0.5*cos(angle*3)+rand(0,0.3),angle+angle1+rand(-2,2),25,0);
	SetShotColor(255,255,255);
	angle+=360/13;
	}
angle1-=5;
PlaySE(SEshots5);
}

if(time%90==0 && time>=90){
let angle=90-50+rand(-10,10);
	loop(10){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX-10,GetY-25);
	Obj_SetAngle(shot1,angle);
	Obj_SetSpeed(shot1,2.5);
	ObjShot_SetGraphic(shot1,39);
	bullet1=bullet1~[shot1];
	bounce1=bounce1~[shot1];
	bounce1[length(bullet1)-1]=0;
	angle+=100/9;
	}
PlaySE(SEthrow1);
usespell=20;
}

let i=0;
while (i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){ bullet1=erase(bullet1,i); bounce1=erase(bounce1,i); i--; }
	else{
		let obj=bullet1[i];
		if(Obj_GetX(obj)<=minx && bounce1[i]==0){
		Obj_SetAngle(obj,180-Obj_GetAngle(obj));
		Obj_SetX(obj,Obj_GetX(obj)+1); ObjShot_SetGraphic(bullet1[i],38); bounce1[i]=1;
		if(playsound==0){ PlaySE(SEreflect2); playsound=7; }
		}
		if(Obj_GetX(obj)>=maxx && bounce1[i]==0){
		Obj_SetAngle(obj,180-Obj_GetAngle(obj));
		Obj_SetX(obj,Obj_GetX(obj)-1); ObjShot_SetGraphic(bullet1[i],38); bounce1[i]=1;
		if(playsound==0){ PlaySE(SEreflect2); playsound=7; }
		}
	}
i++;
}
if(playsound>0){ playsound--; } if(playsound<0){ playsound=0; }

} //Normal

//=============================================================================================================

if(GetCommonData("Difficulty")==3){

if(time%8==0 && time>=60){
let angle=0;
	loop(16){
	let color=200+50*cos(angle*3);
	SetShotColor(color,color,color);
	CreateShot01(GetX,GetY-15,2+0.7*cos(angle*3)+rand(0,0.3),angle+angle1+rand(-2,2),25,0);
	SetShotColor(255,255,255);
	angle+=360/16;
	}
angle1-=6;
PlaySE(SEshots5);
}

if(time%60==0 && time>=90){
let angle=90-60+rand(-10,10);
	loop(12){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX-10,GetY-25);
	Obj_SetAngle(shot1,angle);
	Obj_SetSpeed(shot1,2.5);
	ObjShot_SetGraphic(shot1,39);
	bullet1=bullet1~[shot1];
	bounce1=bounce1~[shot1];
	bounce1[length(bullet1)-1]=0;
	angle+=120/11;
	}
PlaySE(SEthrow1);
usespell=20;
}

let i=0;
while (i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){ bullet1=erase(bullet1,i); bounce1=erase(bounce1,i); i--; }
	else{
		let obj=bullet1[i];
		if(Obj_GetX(obj)<=minx && bounce1[i]==0){
		Obj_SetAngle(obj,180-Obj_GetAngle(obj));
		Obj_SetX(obj,Obj_GetX(obj)+1); ObjShot_SetGraphic(bullet1[i],38); bounce1[i]=1;
		if(playsound==0){ PlaySE(SEreflect2); playsound=7; }
		}
		if(Obj_GetX(obj)>=maxx && bounce1[i]==0){
		Obj_SetAngle(obj,180-Obj_GetAngle(obj));
		Obj_SetX(obj,Obj_GetX(obj)-1); ObjShot_SetGraphic(bullet1[i],38); bounce1[i]=1;
		if(playsound==0){ PlaySE(SEreflect2); playsound=7; }
		}
	}
i++;
}
if(playsound>0){ playsound--; } if(playsound<0){ playsound=0; }

} //Hard

//=============================================================================================================

if(GetCommonData("Difficulty")==4){

if(time%6==0 && time>=60){
let angle=0;
	loop(18){
	let color=200+50*cos(angle*3);
	SetShotColor(color,color,color);
	CreateShot01(GetX,GetY-15,2.2+0.7*cos(angle*3)+rand(0,0.3),angle+angle1+rand(-2,2),25,0);
	SetShotColor(255,255,255);
	angle+=360/18;
	}
angle1-=7;
PlaySE(SEshots5);
}

if(time%60==0 && time>=90){
let angle=90-70+rand(-10,10);
	loop(15){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX-10,GetY-25);
	Obj_SetAngle(shot1,angle);
	Obj_SetSpeed(shot1,2.5);
	ObjShot_SetGraphic(shot1,39);
	bullet1=bullet1~[shot1];
	bounce1=bounce1~[shot1];
	bounce1[length(bullet1)-1]=0;
	angle+=140/14;
	}
PlaySE(SEthrow1);
usespell=20;
}

let i=0;
while (i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){ bullet1=erase(bullet1,i); bounce1=erase(bounce1,i); i--; }
	else{
		let obj=bullet1[i];
		if(Obj_GetX(obj)<=minx && bounce1[i]==0){
		Obj_SetAngle(obj,180-Obj_GetAngle(obj));
		Obj_SetX(obj,Obj_GetX(obj)+1); ObjShot_SetGraphic(bullet1[i],38); bounce1[i]=1;
		if(playsound==0){ PlaySE(SEreflect2); playsound=7; }
		}
		if(Obj_GetX(obj)>=maxx && bounce1[i]==0){
		Obj_SetAngle(obj,180-Obj_GetAngle(obj));
		Obj_SetX(obj,Obj_GetX(obj)-1); ObjShot_SetGraphic(bullet1[i],38); bounce1[i]=1;
		if(playsound==0){ PlaySE(SEreflect2); playsound=7; }
		}
	}
i++;
}
if(playsound>0){ playsound--; } if(playsound<0){ playsound=0; }

} //Lunatic


time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);

#include_function "script/Functions/HealthBar.txt";
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }

	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	if(GetLife>0){ DrawGraphic(GetX,GetY); }
}
 
@Finalize{
}

}